package com.wgo.precise.client.ui.controller;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;


/**
 * @author Petter L. H. Eide <petter@eide.biz>
 * @version $Rev$ $Date$
 */
public enum PrecisePluginImage {
	
	IMG_HORIZONTAL ( "th_horizontal.gif" ),
	IMG_VERTICAL ( "th_vertical.gif" ),
	IMG_STAKEHOLDER ( "stakeholder.png" ),
	IMG_CREATE_STAKEHOLDER ( "create_stakeholder.png" ),
	IMG_PROJECT ( "project.png" ),
	IMG_CREATE_PROJECT ( "create_project.png" ),
	IMG_REQUIREMENT ( "requirement.png" ),
	IMG_CREATE_REQUIREMENT ( "create_requirement.png" ),
	IMG_PROPERTY_SET ( "property_set.png" ),
	IMG_CREATE_PROPERTY_SET ( "create_property_set.png" ),
	IMG_LOGIN ( "login.png" ),
	IMG_LOGOUT ( "logout.png" ),
	IMG_TABLE_EDITOR ( "table_editor.png" )
	;

	private String imageName;
	private Image image;
	private ImageDescriptor imageDescriptor;
	
	private PrecisePluginImage(String imageName) {
		this.imageName = imageName;
//		imageDescriptor = ImageDescriptor.createFromFile(null, Registry.IMAGES_PATH + imageName);
		imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(Registry.PLUGIN_ID, Registry.IMAGES_PATH + imageName);
		if (null == imageDescriptor) {
			imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(Registry.PLUGIN_ID, "target/classes/icons/" + imageName);
		}
		if (null != imageDescriptor) {
			image = imageDescriptor.createImage();
		} else {
			image = null;
			RequirementPlugin.log(new ModelStatus(IStatus.WARNING, "Image " + Registry.IMAGES_PATH + imageName + " not found."));
			imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
		}
	}

	public Image getImage() {
		return image;
	}
	
	public ImageDescriptor getImageDescriptor() {
		return imageDescriptor;
	}

	public String getImageName() {
		return imageName;
	}
}
